package com.wd.live.myapp;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import com.alibaba.android.arouter.launcher.ARouter;
import com.amap.api.location.AMapLocationClient;
import com.amap.apis.utils.core.api.AMapUtilCoreApi;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMOptions;
import com.tencent.mmkv.MMKV;
import com.wd.live.module_base.net.util.UserAddressUtil;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;


//import com.alibaba.android.arouter.launcher.ARouter;

public class MyApp extends Application {
    public static Context context=null;
    private AMapLocationClient mClient;

    @Override
    public void onCreate() {
        super.onCreate();
        context=this;
        if (isDebug()) { // 这两行必须写在init之前，否则这些配置在init过程中将无效
            ARouter.openLog();     // 打印日志
            ARouter.openDebug();   // 开启调试模式(如果在InstantRun模式下运行，必
            //开启调试模式！线上版本需要关闭,否则有安全风险)
        }
        ARouter.init(this);
        // 尽可能早，推荐在Application中初始化
//        UserAddressUtil.updatePrivacyAgree(context,true);
//        UserAddressUtil.updatePrivacyShow(context,true,true);
        AMapLocationClient.updatePrivacyAgree(context,true);
        AMapLocationClient.updatePrivacyShow(context,true,true);

//        try {
//            mClient = new AMapLocationClient(context);
//        }catch (Exception e){
//        }
//        if (mClient != null){
//
//        }

        /**
         * 基础库设置是否允许采集个人及设备信息
         * @param collectEnable: true 允许采集 false 不允许采集
         */
        AMapUtilCoreApi.setCollectInfoEnable(false);


        //初始化微信
//        initWeChat();
//        initSVGA();
        //初始化 MMKV
        String initialize = MMKV.initialize(this);
//        Log.i("======= ", initialize);

//        Log.i("TAGnnnn", "onCreate: "+s);
        huanXin();
    }

    private void huanXin(){
        EMOptions options = new EMOptions();
        options.setAppKey("1196240604175830#demo");
// 其他 EMOptions 配置。
        EMClient.getInstance().init(this, options);

    }

    private boolean isDebug() {
        return true;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//        MultiDex.install(this);
    }

    private void initWeChat() {
//        WXUtil.regToWx(this);
    }

    private void initSVGA() {
//        SVGAParser.Companion.shareParser().init(this);
    }
    //获取高德定位的sha1
    private String sHA1(Context context){
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
            byte[] cert = info.signatures[0].toByteArray();
            MessageDigest md = MessageDigest.getInstance("SHA1");
            byte[] publicKey = md.digest(cert);
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < publicKey.length; i++) {
                String appendString = Integer.toHexString(0xFF & publicKey[i])
                        .toUpperCase(Locale.US);
                if (appendString.length() == 1)
                    hexString.append("0");
                hexString.append(appendString);
                hexString.append(":");
            }
            String result = hexString.toString();
            return result.substring(0, result.length()-1);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

}
